package com.huluobo.mvvm2003ademo.repositories;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm2003ademo.model.Product;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Created by lc on 2022/9/12.
 */
public class ShopRepo {
    private MutableLiveData<List<Product>> mutableProductList;

    public LiveData<List<Product>> getProducts() {
        if (mutableProductList == null) {
            mutableProductList = new MutableLiveData<>();
            loadProducts();
        }
        return mutableProductList;
    }

    private void loadProducts() {
        List<Product> productList = new ArrayList<>();
        productList.add(new Product(UUID.randomUUID().toString(), "Apple MacBook Air 13.3", 1299, true, "https://img11.360buyimg.com/n7/jfs/t2968/143/2485546147/238650/70df281e/57b12a31N8f4f75a3.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "Apple MacBook Pro 13.3", 1399, false, "https://img13.360buyimg.com/n7/jfs/t2590/338/4222589387/237425/25e40fb/57b12ac6N61374a75.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "Apple MacBook Pro 15.4", 699, false, "https://img10.360buyimg.com/n7/jfs/t3499/165/739574790/179345/251c51d4/58126465Na27a9bf0.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "Apple MacBook Air 13.3", 699, true, "https://img13.360buyimg.com/n1/jfs/t5821/151/4295371754/246251/29179c11/594a3eabNbf7fceec.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "Apple MacBook Pro", 899, true, "https://img14.360buyimg.com/n5/s450x450_jfs/t3397/55/762020838/184157/7e507d32/58131c17Nb108ca54.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "Apple MacBook Air 13.3", 599, true, "https://img11.360buyimg.com/n7/jfs/t2968/143/2485546147/238650/70df281e/57b12a31N8f4f75a3.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "Apple MacBook Air 13.3", 899, false, "https://img13.360buyimg.com/n1/jfs/t5821/151/4295371754/246251/29179c11/594a3eabNbf7fceec.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "国行 Apple MacBook Pro", 1299, true, "https://img.alicdn.com/imgextra/i3/1669409267/TB2bMSccXXXXXbVXXXXXXXXXXXX_!!1669409267.jpg_430x430q90.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "ThinkPad New S2", 1499, true, "https://img14.360buyimg.com/n1/s450x450_jfs/t5446/184/2581563799/286954/9ebfad09/591bddbcNc724d048.jpg"));
        productList.add(new Product(UUID.randomUUID().toString(), "联想（ThinkPad）E460", 1399, true, "https://img12.360buyimg.com/n1/s450x450_jfs/t3439/192/665209614/82997/ce6c3ad8/58107973Na856a8e1.jpg"));
        //在这里相当于网络请求的那一层,可以获取数据源的list赋值给mutableProductList
        mutableProductList.setValue(productList);
    }
}
